<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class MY_Controller extends MX_Controller {

    //Page info
    protected $data = Array();
    protected $pageName = FALSE;
    protected $template = "main";
    protected $hasNav = true;
    protected $hasIntro = true;
    protected $introStyle = "success";
    protected $hasSubfooter = true;
    protected $hasFooter = true;
    protected $hasHeader = true;
    protected $introUrlVolver = null;
    //Page contents
    protected $javascript1 = array();
    protected $javascript2 = array();
    protected $css = array();
    protected $fonts = array();
    //Page Meta
    protected $title = FALSE;
    protected $description = FALSE;
    protected $keywords = FALSE;
    protected $author = FALSE;
    protected $title_intro = "";
    protected $desc_intro = "";
    protected $color = null;

    function __construct() {

        parent::__construct();
        $this->data["uri_segment_1"] = $this->uri->segment(1);
        $this->data["uri_segment_2"] = $this->uri->segment(2);
        $this->title = $this->config->item('site_title');
        $this->author = $this->config->item('site_author');

        $this->pageName = strToLower(get_class($this));
    }

    protected function _render($view) {
        
        $this->description = (!$this->description ? $this->config->item('site_description') : $this->description);
        $this->keywords = (!$this->keywords ? $this->config->item('site_keywords') : $this->keywords);
        //static
        $toTpl["javascript1"] = $this->javascript1;
        $toTpl["javascript2"] = $this->javascript2;
        $toTpl["css"] = $this->css;
        $toTpl["fonts"] = $this->fonts;

        //meta
        $toTpl["title"] = $this->title;
        $toTpl["description"] = $this->description;
        $toTpl["keywords"] = $this->keywords;
        $toTpl["author"] = $this->author;

        //data
        $toBody["content_body"] = $this->load->view($view, array_merge($this->data, $toTpl), true);

        $toMenu["pageName"] = $this->pageName;
        //nav menu
        if ($this->hasNav) {
            $toMenu['nav'] = $this->load->view("base/nav", $toMenu, true);
        }
        if ($this->hasHeader) {
            $toBody["header"] = $this->load->view("base/header", $toMenu, true);
        }
        $toBody["basejs"] = $this->load->view("base/basejs", $this->data, true);
        if ($this->hasSubfooter) {
            $toBody["subfooter"] = $this->load->view("base/subfooter", '', true);
        }
        if($this->hasFooter){
            $toBody["footer"] = $this->load->view("base/footer", '', true);
        }
        $toBody['estilo'] = $this->introStyle;
        $toTpl["body"] = $this->load->view("base/" . $this->template, $toBody, true);
        
        if($this->color != null){
            $toTpl["color"] = $this->color;
        }
        //render view
        $this->load->view("base/skeleton", $toTpl);
    }
    
    protected function _renderback($view) {
        //static
        $toTpl["javascript1"] = $this->javascript1;
        $toTpl["javascript2"] = $this->javascript2;
        $toTpl["css"] = $this->css;
        $toTpl["fonts"] = $this->fonts;

        //meta
        $toTpl["title"] = $this->title;

        //data
        $toBody["content_body"] = $this->load->view($view, array_merge($this->data, $toTpl), true);

        $toMenu["pageName"] = $this->pageName;
        //nav menu
        if ($this->hasNav) {
            $toBody['intro'] = $this->load->view("back/intro", $toMenu, true);
        }
        if ($this->hasHeader) {
            $toBody["header"] = $this->load->view("back/header", $toMenu, true);
        }
        $toBody["basejs"] = $this->load->view("back/basejs", $this->data, true);
        if($this->hasFooter){
            $toBody["footer"] = $this->load->view("back/footer", '', true);
        }
        $toBody["sidebar"] = $this->load->view("back/sidebar", '', true);
        $toTpl["body"] = $this->load->view("back/" . $this->template, $toBody, true);
        //render view
        $this->load->view("back/skeleton", $toTpl);
    }

    protected function model($models = null) {
        if ($models == null) {
            return null;
        }
        foreach ($models as $file) {
            $this->load->model($file);
        }
    }
}
